//
//  LYDPopoverView.m

#import "FilterView.h"
#import "FilterTableViewCell.h"
#import "FilterSecondView.h"
#import "FilterSecondLevelModel.h"
#define kUIScreenHeight [UIScreen mainScreen].bounds.size.height
#define kUIScreenWidth [UIScreen mainScreen].bounds.size.width
@interface FilterView () <UITableViewDataSource,UITableViewDelegate,FilterSecondViewDelegate>
{
    NSMutableArray *firstLevelModelArray;
    NSMutableArray *currentArray;
    NSMutableArray *selectArr;
    NSString *typeStr;
    NSUInteger parentIndex;
    BOOL clearAll;
}

@property (nonatomic, strong) UITableView *tableView;

//@property (nonatomic, assign) LYDPopoverViewDirection direction;

@property (nonatomic, strong) UIView *theContentView;

@property (nonatomic, strong) UIButton *alphaBtn;

@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIButton *restartBtn;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *confirmBtn;
@property (nonatomic, strong) UILabel *topLineLabel;
@property (nonatomic, assign) CGSize size;

@end

@implementation FilterView

#pragma mark - settet&getter


#pragma mark - 初始化类方法

+ (instancetype)FilterViewWithSize:(CGSize)size
{
    
    FilterView *popView = [[self alloc] init];
    popView.size =size;
    return popView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setAllDataArray:(NSMutableArray *)allDataArray{
    _allDataArray = allDataArray;
    [currentArray removeAllObjects];
    if (allDataArray.count > 0) {
        currentArray = allDataArray;
        [_tableView reloadData];
    }
}
-(void)setSelectedSearchBeansArray:(NSMutableArray *)selectedSearchBeansArray{
   
    if (selectedSearchBeansArray.count>0) {
        [currentArray removeAllObjects];
        [selectArr removeAllObjects];
        NSLog(@" selectedSearchBeansArray>>>>>==%@",selectedSearchBeansArray);
        for (NSDictionary* dicc in selectedSearchBeansArray ) {
            // 这里为了处理多选
            
            BOOL isContent = [[dicc allKeys] containsObject:@"items"];
            
            if ([[dicc objectForKey:@"isSingle"] isEqualToString:@"N"] && isContent == YES) {
                NSArray *imgArray=dicc[@"items"];
                NSMutableArray *arr = [NSMutableArray array];
                for (int i = 0; i < imgArray.count; i ++) {
                    
                    NSMutableDictionary *dic = imgArray[i];
                    
                     FilterSecondLevelModel *secondLevelModel=[FilterSecondLevelModel dataModelWithDict:dic];
                    [arr addObject:secondLevelModel];
                }
                
                [currentArray addObject:arr];
                
                
                
//                NSArray *imgArray=dicc[@"items"];
//                for (NSDictionary *dic in imgArray) {
//                    FilterSecondLevelModel *secondLevelModel=[FilterSecondLevelModel dataModelWithDict:dic];
////                    [selectArr addObject:secondLevelModel];
//                }
//                [currentArray addObject:selectArr];
            } else{
                NSArray *imgArray=dicc[@"items"];
                for (NSDictionary *dic in imgArray) {
                    FilterSecondLevelModel *secondLevelModel=[FilterSecondLevelModel dataModelWithDict:dic];
                    [currentArray addObject:secondLevelModel];
                }
            }
        }
        [_tableView reloadData];
    }
}
-(void)requestFilterList {
    
//    [currentArray removeAllObjects];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:self.typeStr forKey:@"filterType"];
    [MBProgressHUD showIndeterminateHudSub:@"" delay:30 view:self];
   
    [HttpRequest requestData:@"report/advancedFilterList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [MBProgressHUD hideProgressHUDInternal:self];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                NSLog(@"arrr#######====%@",arrr);
                for (NSDictionary* dicc in arrr ) {
                    
                    FilterFirstLevelModel *firstLevelModel=[FilterFirstLevelModel dataModelWithDict:dicc];
                    [firstLevelModelArray addObject:firstLevelModel];
                    
                    FilterSecondLevelModel *secondModel=[FilterSecondLevelModel dataModelWithDict:dicc[@"current"]];
                    [currentArray addObject:secondModel];
                }

                [_tableView reloadData];
                
            }else{
                [MBProgressHUD hideProgressHUDInternal:self];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [MBProgressHUD showTextHudSub:requestResultStr view:self];
            }
            
        } else {
            
            [MBProgressHUD hideProgressHUDInternal:self];
            [MBProgressHUD showTextHudSub:severDataDict.resultStr view:self];
        }
        
    }];
    
}

- (void)setup
{
    clearAll=NO;
    firstLevelModelArray = [NSMutableArray array];
    currentArray = [NSMutableArray array];
    selectArr = [NSMutableArray array];
    _alphaBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [_alphaBtn addTarget:self action:@selector(alphaBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_alphaBtn setBackgroundColor: [UIColor blackColor]];
    _alphaBtn.alpha=0.6;
    [self addSubview:_alphaBtn];
    
    _theContentView=[[UIView alloc] init];
    _theContentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_theContentView];
    
    _cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelBtn setTitleColor:[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
    [_cancelBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [_cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [_theContentView addSubview:_cancelBtn];
    
   _restartBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//    [_restartBtn setTitleColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
    [_restartBtn setTitleColor:lanse forState:UIControlStateNormal];
    [_restartBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
     [_restartBtn addTarget:self action:@selector(restartBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_restartBtn setTitle:@"重置" forState:UIControlStateNormal];
    [_theContentView addSubview:_restartBtn];
    
    _titleLabel=[[UILabel alloc] init];
    _titleLabel.text=@"筛选";
    _titleLabel.textColor=[UIColor blackColor];
    [_titleLabel setFont:[UIFont systemFontOfSize:17]];
    [_theContentView addSubview:_titleLabel];
    
    _topLineLabel=[[UILabel alloc] init];
    [_topLineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [_theContentView addSubview:_topLineLabel];
    
   _confirmBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//    [_confirmBtn setBackgroundColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0]];
    [_confirmBtn setBackgroundColor:lanse];
    [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_confirmBtn.titleLabel setFont:[UIFont systemFontOfSize:17]];
    [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [_theContentView addSubview:_confirmBtn];

    
    _tableView = [[UITableView alloc] init];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_theContentView addSubview:_tableView];
    
    
}
-(void)cancelBtnClick {
    
//    NSMutableArray *searchBeans=[NSMutableArray array];
//    if ([self.delegate respondsToSelector:@selector(confirmFilter:)]) {
//        [self.delegate confirmFilter: searchBeans];
//    }
    if ([self.delegate respondsToSelector:@selector(cancelPop)]) {
        [self.delegate cancelPop];
    }
    [self dismiss];

}
-(void)restartBtnClick
{
    clearAll=YES;
    [firstLevelModelArray removeAllObjects];
    [selectArr removeAllObjects];
    [currentArray removeAllObjects];
    [self requestFilterList];
}
-(void)confirmBtnClick
{
    NSMutableArray *searchBeans=[NSMutableArray array];
    for (int i=0; i<firstLevelModelArray.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        FilterFirstLevelModel *firstModel=firstLevelModelArray[i];
        [dic setValue:firstModel.typeCode forKey:@"typeCode"];
        [dic setValue:firstModel.isSingle forKey:@"isSingle"];
        [dic setValue:firstModel.typeName forKey:@"typeName"];
        [dic setValue:firstModel.dataType forKey:@"dataType"];
        
        
//        if ([currentArray[indexPath.row] isKindOfClass:[NSMutableArray class]]) {
//            NSMutableArray *modelArr = currentArray[indexPath.row];
//            FilterSecondLevelModel *secondModel = modelArr[0];
//            if (modelArr.count == 1) {
//                cell.itemNameLabel.text=secondModel.itemName;
//            } else{
//                cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
//            }
//
//        }
//
        
        if ([firstModel.isSingle isEqualToString:@"N"]) {
            
            if ([currentArray[i] isKindOfClass:[NSMutableArray class]]) {
                NSMutableArray *modelArr = currentArray[i];
                NSMutableArray *itemsArray=[NSMutableArray array];
                if (modelArr.count > 0) {
                    for (int i = 0; i < modelArr.count; i ++) {
                        NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
                        FilterSecondLevelModel *secondModel=modelArr[i];
                        [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
                        [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
                        [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
                        [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
                        [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
                        [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
                        [itemsArray addObject:itemsDic];
                    }
                }
                [dic setObject:itemsArray forKey:@"items"];
    
            }
            
//            NSMutableArray *itemsArray=[NSMutableArray array];
//            for (int i = 0; i < selectArr.count; i ++) {
//
//                NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
//                FilterSecondLevelModel *secondModel=selectArr[i];
//                [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
//                [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
//                [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
//                [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
//                [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
//                [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
//                [itemsArray addObject:itemsDic];
//
//            }
//            [dic setObject:itemsArray forKey:@"items"];
//
        } else{
            NSMutableArray *itemsArray=[NSMutableArray array];
            FilterSecondLevelModel *secondModel=currentArray[i];
            NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
            [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
            [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
            [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
            [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
            [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
            [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
            [itemsArray addObject:itemsDic];
            [dic setObject:itemsArray forKey:@"items"];
        }
        
//        if ([firstModel.isSingle isEqualToString:@"N"] && selectArr.count > 0) {
//            NSMutableArray *itemsArray=[NSMutableArray array];
//            for (int i = 0; i < selectArr.count; i ++) {
//
//                NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
//                FilterSecondLevelModel *secondModel=selectArr[i];
//                [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
//                [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
//                [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
//                [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
//                [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
//                [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
//                [itemsArray addObject:itemsDic];
//
//            }
//            [dic setObject:itemsArray forKey:@"items"];
//
//        } else{
//            NSMutableArray *itemsArray=[NSMutableArray array];
//            FilterSecondLevelModel *secondModel=currentArray[i];
//            NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
//            [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
//            [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
//            [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
//            [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
//            [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
//            [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
//            [itemsArray addObject:itemsDic];
//            [dic setObject:itemsArray forKey:@"items"];
//        }

//            NSMutableArray *itemsArray=[NSMutableArray array];
//            FilterSecondLevelModel *secondModel=currentArray[i];
//            NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
//            [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
//            [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
//            [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
//            [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
//            [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
//            [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
//            [itemsArray addObject:itemsDic];
//            [dic setObject:itemsArray forKey:@"items"];

        

        [searchBeans addObject:dic];
//        NSLog(@"itemname=====%@",secondModel.itemName);
    }
    NSLog(@"searchBeans>>>>>==%@",searchBeans);
    if (clearAll) {
        [searchBeans removeAllObjects];
    }
    if ([self.delegate respondsToSelector:@selector(confirmFilter:)]) {
        [self.delegate confirmFilter:searchBeans];
    }
    
    if ([self.delegate respondsToSelector:@selector(confirmFilter: andAllData:)]) {
        [self.delegate confirmFilter:searchBeans andAllData:currentArray];
    }
    [self dismiss];
    
}

#pragma mark - tableView代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 53;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return firstLevelModelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    NSLog(@"%ld", indexPath.row);
    FilterFirstLevelModel *firstModel = firstLevelModelArray[indexPath.row];
    static NSString * const  CellIdentifier = @"FilterTableViewCellIdentifier";
    FilterTableViewCell *cell=( FilterTableViewCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FilterTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    cell.model = firstModel;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if ([currentArray[indexPath.row] isKindOfClass:[NSMutableArray class]]) {
        NSMutableArray *modelArr = currentArray[indexPath.row];
//        if (modelArr.count > 0) {
//            FilterSecondLevelModel *secondModel = modelArr[0];
//            if (modelArr.count == 1) {
//                cell.itemNameLabel.text=secondModel.itemName;
//            } else{
//                cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
//            }
//        }
        FilterSecondLevelModel *secondModel = modelArr[0];
        if (modelArr.count == 1) {
            cell.itemNameLabel.text=secondModel.itemName;
        } else{
            cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
        }
        

    } else{
        FilterSecondLevelModel *secondModel=currentArray[indexPath.row];
        cell.itemNameLabel.text=secondModel.itemName;
    }
    
    
    /*
    // 这里为了处理多选
    //  indexPath.row == parentIndex
    if ([firstModel.isSingle isEqualToString:@"N"] && selectArr.count > 0 ) {
        NSLog(@"----%ld", indexPath.row);
//        NSMutableArray *modelArr = currentArray[indexPath.row];
//        FilterSecondLevelModel *secondModel = modelArr[0];
//        if (selectArr.count == 1) {
//            cell.itemNameLabel.text=secondModel.itemName;
//        } else{
//            cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
//        }
        
        
        
        if ([currentArray[indexPath.row] isKindOfClass:[NSMutableArray class]]) {
            NSMutableArray *modelArr = currentArray[indexPath.row];
            FilterSecondLevelModel *secondModel = modelArr[0];
            if (selectArr.count == 1) {
                cell.itemNameLabel.text=secondModel.itemName;
            } else{
                cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
            }
            
        }
//        else{
//            FilterSecondLevelModel *secondModel=currentArray[indexPath.row];
//            cell.itemNameLabel.text=secondModel.itemName;
//        }
        
        
       
        
    } else{
//        FilterSecondLevelModel *secondModel=firstModel.secondModelArray[indexPath.row];
//        cell.itemNameLabel.text=secondModel.itemName;

        NSLog(@"非选中行 == %ld", (long)indexPath.row);
//        FilterSecondLevelModel *secondModel=currentArray[indexPath.row];
//        cell.itemNameLabel.text=secondModel.itemName;
//        if ([currentArray[indexPath.row] isKindOfClass:[NSMutableArray class]]) {
//            NSMutableArray *modelArr = currentArray[indexPath.row];
//            FilterSecondLevelModel *secondModel = modelArr[0];
//            if (selectArr.count == 1) {
//                cell.itemNameLabel.text=secondModel.itemName;
//            } else{
//                cell.itemNameLabel.text= [NSString stringWithFormat:@"%@,...", secondModel.itemName];
//            }
//
//        } else{
            FilterSecondLevelModel *secondModel=currentArray[indexPath.row];
            cell.itemNameLabel.text=secondModel.itemName;
//        }
    }

    */
    
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    FilterFirstLevelModel *firstModel=firstLevelModelArray[indexPath.row];
    
    
    NSMutableArray *searchBeans=[NSMutableArray array];
    if ([firstModel.typeCode isEqualToString:@"i.ItemTypeCode"]&&indexPath.row>=1) {
        
        
       
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            FilterFirstLevelModel *firstModel=firstLevelModelArray[indexPath.row-1];
            [dic setValue:firstModel.typeCode forKey:@"typeCode"];
            [dic setValue:firstModel.isSingle forKey:@"isSingle"];
            [dic setValue:firstModel.typeName forKey:@"typeName"];
            [dic setValue:firstModel.dataType forKey:@"dataType"];
            
            NSMutableArray *itemsArray=[NSMutableArray array];
            FilterSecondLevelModel *secondModel=currentArray[indexPath.row-1];
            NSMutableDictionary *itemsDic= [NSMutableDictionary dictionary];
            [itemsDic setObject:secondModel.itemName forKey:@"itemName"];
            [itemsDic setObject:secondModel.itemValue forKey:@"itemValue"];
            [itemsDic setObject:secondModel.minValue forKey:@"minValue"];
            [itemsDic setObject:secondModel.maxValue forKey:@"maxValue"];
            [itemsDic setObject:secondModel.isCustom forKey:@"isCustom"];
            [itemsDic setObject:secondModel.isRange forKey:@"isRange"];
            [itemsArray addObject:itemsDic];
            [dic setObject:itemsArray forKey:@"items"];
            [searchBeans addObject:dic];
        
    }

    parentIndex=indexPath.row;
    
    NSLog(@"row == %ld", indexPath.row);
    FilterSecondLevelModel *secondModel=currentArray[indexPath.row];
    FilterSecondView *secondView=[[FilterSecondView alloc] init:firstModel.secondModelArray secondLevelModel:secondModel title:firstModel.typeName isLikeSearch:firstModel.isLikeSearch  totalCount:firstModel.totalCount typeCode:firstModel.typeCode itemsArry:searchBeans andIsSingle:firstModel.isSingle];
    secondView.frame=self.frame;
    secondView.delegate=self;
    secondView.typeStr=self.typeStr;
    secondView.isSingle = firstModel.isSingle;
    
    
    if ([currentArray[indexPath.row] isKindOfClass:[NSMutableArray class]]) {
        
        NSMutableArray *arrr = currentArray[indexPath.row];
        secondView.didSelectArr = arrr;
    }
    
    // 这里为了处理多选
//    if (selectArr.count > 0) {
//        secondView.didSelectArr = selectArr;
//    }
    secondView.parentIndex=[NSString stringWithFormat:@"%ld",parentIndex];
    [self addSubview:secondView];
}

#pragma mark FilterSecondViewDelegate
- (void)FilterSecondView:(FilterSecondLevelModel *)secondLevelModel cellIndex:(NSInteger)cellIndex {
    
    [currentArray replaceObjectAtIndex:parentIndex withObject:secondLevelModel];
    
    // 这里为了处理多选
    FilterFirstLevelModel *firstModel=firstLevelModelArray[parentIndex];
    if ([firstModel.isSingle isEqualToString:@"N"] && [secondLevelModel.itemName  isEqualToString:@"全部"]) {
        [selectArr removeAllObjects];
    }
    
    [_tableView reloadData];
}

// 这里为了处理多选
- (void)FilterSecondViewWithArr:(NSMutableArray *)modelArr{
    selectArr = modelArr;
    [currentArray replaceObjectAtIndex:parentIndex withObject:modelArr];
    [_tableView reloadData];
}



-(void)alphaBtnClick {
    
    [self dismiss];
}


- (void)show {
    
    // 获得主窗口
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame= CGRectMake(kUIScreenWidth, 0, kUIScreenWidth, kUIScreenHeight);
    [window addSubview:self];
    [UIView animateWithDuration:0.6 animations:^{
        self.frame= CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight);
    }];
    [self requestFilterList];
    
}

- (void)dismiss {
    [UIView animateWithDuration:0.6 animations:^{
        self.frame= CGRectMake(kUIScreenWidth, 0, kUIScreenWidth, kUIScreenHeight);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    [_alphaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
        make.width.equalTo(@0);
    }];
//    [_theContentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_alphaBtn.mas_right);
//        make.top.equalTo(self.mas_top);
//        make.bottom.equalTo(self.mas_bottom);
//        make.right.equalTo(self.mas_right);
//    }];
    
    if (is_iPhoneX) {
        [_theContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_alphaBtn.mas_right);
            make.top.equalTo(self.mas_top).offset(0);
            make.bottom.equalTo(self.mas_bottom);
            make.right.equalTo(self.mas_right);
        }];
        
        [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_theContentView.mas_left).with.offset(10);
            make.top.equalTo(_theContentView.mas_top).with.offset(25+24);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        
        [_restartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_theContentView.mas_right).with.offset(-10);
            make.top.equalTo(_theContentView.mas_top).with.offset(25+24);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_theContentView.mas_centerX);
            make.top.equalTo(_theContentView.mas_top).with.offset(25+24);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        
        [_topLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_theContentView.mas_left).with.offset(0);
            make.top.equalTo(_theContentView.mas_top).with.offset(63+24);
            make.height.equalTo(@0.5);
            make.right.equalTo(_theContentView.mas_right).with.offset(0);
        }];
    } else{
        [_theContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_alphaBtn.mas_right);
            make.top.equalTo(self.mas_top);
            make.bottom.equalTo(self.mas_bottom);
            make.right.equalTo(self.mas_right);
        }];
        [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_theContentView.mas_left).with.offset(10);
            make.top.equalTo(_theContentView.mas_top).with.offset(25);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        
        [_restartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_theContentView.mas_right).with.offset(-10);
            make.top.equalTo(_theContentView.mas_top).with.offset(25);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_theContentView.mas_centerX);
            make.top.equalTo(_theContentView.mas_top).with.offset(25);
            make.height.equalTo(@30);
            make.width.equalTo(@40);
        }];
        
        [_topLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_theContentView.mas_left).with.offset(0);
            make.top.equalTo(_theContentView.mas_top).with.offset(63);
            make.height.equalTo(@0.5);
            make.right.equalTo(_theContentView.mas_right).with.offset(0);
        }];
    }
    
    
    
    [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_theContentView.mas_left);
        make.bottom.equalTo(_theContentView.mas_bottom).offset(-TabbarSafeBottomMargin);
        make.height.equalTo(@45);
        make.right.equalTo(_theContentView.mas_right);
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_theContentView.mas_left);
        make.top.equalTo(_topLineLabel.mas_bottom);
        make.bottom.equalTo(_confirmBtn.mas_top);
        make.right.equalTo(_theContentView.mas_right);
    }];
}


@end
